package com.happyclub.lbjcontroller;

import com.happyclub.lbj.service.IProduct;
import com.happyclub.lbj.service.IProductColor;
import com.happyclub.lbj.service.IProductSize;
import com.happyclub.pojo.TbProduct;
import com.happyclub.pojo.TbProductColor;
import com.happyclub.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 高欢
 * @description TODO
 * @date 2019/4/10
 */
@RestController
@RequestMapping("/productColor")
public class ProductContorller {
    @Autowired
    IProductColor iProductColor;
    @Autowired
    IProduct iProduct;

    @Autowired
    IProductSize iProductSize;

    @RequestMapping(value = "/saveColor",method = RequestMethod.POST)
    public JsonResult saveProductColor(@RequestBody TbProductColor tbProductColor){
        return iProductColor.saveProductColor(tbProductColor);
    }

    @RequestMapping(value = "/delColor/{id}",method = RequestMethod.DELETE)
    public JsonResult delProductColor(@PathVariable String id){
        return iProductColor.delProductColor(id);
    }

    @RequestMapping(value = "/updateColor",method = RequestMethod.PUT)
    public JsonResult updateProductColor(@RequestBody TbProductColor tbProductColor){
        return iProductColor.updateProductColor(tbProductColor);
    }

    @RequestMapping(value = "/findAllColor",method =RequestMethod.GET)
    public JsonResult findAllColor(){
        return iProductColor.findAllProductColor();
    }

    @RequestMapping(value = "/savePro",method = RequestMethod.POST)
    public JsonResult savePro(TbProduct product,@RequestParam("photofile") MultipartFile[] multipartFiles){
        return iProduct.saveProduct(product,multipartFiles);//添加商品成功后,跳转到商品尺寸和颜色选择页面
    }

    //得到所有的尺寸
    @RequestMapping(value = "/findAllSize",method = RequestMethod.GET)
    public JsonResult findAllSize(){
        return iProductSize.findAllSize();
    }

    //保存商品颜色和尺寸,color和size是ID之间用逗号连接起来的
    @RequestMapping(value = "/saveProColorAndSize/{productId}/{color}/{size}",method = RequestMethod.POST)
    public JsonResult saveProColorAndSize(@PathVariable String productId,@PathVariable String color,@PathVariable String size){
        return iProduct.saveProductColorAndSize(productId,color,size);
    }
    //修改商品是否上架
    @RequestMapping(value = "/updateUpper/{proId}/{upper}",method = RequestMethod.PUT)
    public JsonResult updateProUpper(@PathVariable String proId,@PathVariable String upper){
        return iProduct.updateProUpper(proId,Integer.valueOf(upper));
    }

    //查询所有已上架的
    @RequestMapping(value = "/findAllProByUpper",method = RequestMethod.GET)
    public JsonResult findAllPro(){
        return iProduct.findAllProByUpper();
    }

    //点进商品详情时
    @RequestMapping(value = "/findProDetail/{productId}",method = RequestMethod.GET)
    public JsonResult findProDetail(@PathVariable String productId){
        return iProduct.findProDetail(productId);
    }

    @RequestMapping(value = "/addLookNum/{id}",method = RequestMethod.PUT)
    public JsonResult addLookNum(@PathVariable String id){
        return iProduct.addLookNum(id);
    }
}
